<div class="bjui-pageContent">
    <form action="{:U('save_promotion')}" data-callback="dialogFormCall" data-toggle="validate" data-alertmsg="false" class="dialogForm">
        <input type="hidden" name="id" value="{$va.id}"/>
        <input type="hidden" name="type" value="0"/>
        <div class="form-group">
            <label class="x100">活动名称:</label>
            <input type="text" name="name" data-rule="required" value="{$va.name}" />
        </div>
        <div class="form-group clearfix">
            <label class="x100 pull-left">活动图片:</label>
            <div class="pull-left parent_img">
                <if condition="$va.logo eq null">
                <img src="__PU__/images/1584936.jpg" alt="LOGO" width="70" />
                <else/>
                <img src="{$va.logo}" alt="LOGO" width="70" />
                </if>
                <input type="hidden" name="logo" value="{$va.logo}"/>
                <span data-toggle="upload" 
                data-uploader="{:U('Index/upload')}"
                 data-file-type-exts="*.png;*.jpg"
                 data-icon="cloud-upload"
                 data-on-upload-success="upload_callback"
                 data-auto="true"
                 data-button-text="上传图片"
                ></span>
            </div>
        </div>
        <div class="form-group">
            <label class="x100">活动方式:</label>
            <select name="award_type" class="avtype" data-toggle="selectpicker" data-rule="required">
                <option value="0">--请选择--</option>
                <option value="1" <if condition="$va.award_type eq '1'">selected</if>>打折</option>
                <option value="2" <if condition="$va.award_type eq '2'">selected</if>>减价优惠</option>
                <option value="3" <if condition="$va.award_type eq '3'">selected</if>>固定金额</option>
                <option value="4" <if condition="$va.award_type eq '4'">selected</if>>买就送券</option>
            </select>
        </div>
        <div class="form-group sel sel1" style="display: none;">
            <label class="x100">折扣:</label>
            <input type="text" name="award_value_1"  class="w100" value="{$va.award_value}"/> %
            <span class="text-warning">折扣值(1-100 如果打9.5折，请输入95)</span>
        </div>
        <div class="form-group sel sel2" style="display: none;">
            <label class="x100">立减:</label>
            <input type="text" name="award_value_2" class="w100" value="{$va.award_value}"/> 元
        </div>
        <div class="form-group sel sel3" style="display: none;">
            <label class="x100">出售金额:</label>
            <input type="text" name="award_value_3" class="w100" value="{$va.award_value}"/> 元
        </div>
        <div class="form-group sel sel4" style="display: none;">
            <label class="x100">选择优惠券:</label>
            <select name="award_value_4" data-toggle="selectpicker">
                <option value="0">--请选择--</option>
                <volist name="coupon" id="co">
                  <option value="{$co.id}" <if condition="$va['award_value'] eq $co['id']">selected</if>>{$co.name}</option>
                </volist>
            </select>
        </div>
        <div class="form-group">
            <label class="x100">开始时间:</label>
            <input type="text" name="start_time" value="{$va.start_time}"data-rule="required" data-toggle="datepicker" data-pattern="yyyy-MM-dd HH:mm:ss" />
        </div>
        <div class="form-group">
            <label class="x100">结束时间:</label>
            <input type="text" name="end_time" value="{$va.end_time}" data-rule="required" data-toggle="datepicker" data-pattern="yyyy-MM-dd HH:mm:ss" />
        </div>
        <div class="form-group">
            <label class="x100">适用范围:</label>
            <input type="checkbox" name="user_group[]" value="all" id="prom_fanwei1" data-toggle="icheck" data-label="全部用户"  <if condition="in_array('all',$va['user_group'])">checked</if> />
            <volist name="group" id="go">
             <input type="checkbox" name="user_group[]" value="{$go.id}" id="prom_fanwei2" data-toggle="icheck" data-label="{$go.name}"  <if condition="in_array($go['id'],$va['user_group'])">checked</if> />
            </volist>
        </div>
        <div class="form-group">
            <label class="x100">设置商品:</label>
            <input type="hidden" name="pro_id" class="lookup-blue" value="{$va.goods_id}"/>
            <button type="button" class="btn-blue" data-toggle="lookupbtn" data-title="选择商品" data-id="sel_goods" data-url="{:U('Common/goods', array('type'=>2))}" data-width="800" data-height="500">选择</button>
        </div>
        <div class="form-group goods-tables">
            <table class="table table-bordered table-hover table-striped table-top" data-selected-multi="false">
                <thead>
                <tr>
                    <th>商品名称</th>
                    <th>库存</th>
                    <th>售价</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <if condition="$va.goods neq null">
                    <volist name="va['goods']" id="vaa">
	                    <tr data-id="pro_id">
	                        <input type="hidden" name="proid[]" value="{$vaa.id}"/>
	                        <td>{$vaa.name}</td>
	                        <td>{$vaa.store_nums}</td>
	                        <td>{$vaa.sell_price}</td>
	                        <td><button type="button" class="btn btn-red">删</button></td>
	                    </tr>
                    </volist>
                </if>
                </tbody>
            </table>
        </div>
        <div class="form-group clearfix">
            <label class="x100 text-top pull-left">活动介绍:</label>
            <div class="pull-left">
                <textarea name="intro"
                             data-toggle="kindeditor" 
                             data-items="'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
        'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
        'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
        'anchor', 'link', 'unlink', '|', 'about'"
                             style="width: 100%;"
                             >
                             {$va.intro}
                </textarea>
                </div>
        </div>
    </form>
</div>
<script>
    var type = {$va.award_type|default='0'};
    $(function () {
    	type && $('.sel').hide() && $('.sel' + type).show();
       $('.avtype').change(function () {
           this.value && $('.sel').hide() && $('.sel' + this.value).show();
       }) ;
        $('.lookup-blue').on('afterchange.bjui.lookup', function(e, data){
            var result = data.args;
            var arr = [];
            if( result.pro_name.indexOf(',') < 1 ){
                arr.push(result);
            }else{
                for (var item in result){
                    var text = result[item].split(',');
                    if( arr.length < 1 ){
                        for( var index = 0; index < text.length; index++ ){
                            var o = {};
                            o[item] = text[index];
                            arr.push(o);
                        }
                    }else{
                        for(var index = 0 ; index < arr.length ; index++){
                            arr[index][item] = text[index];
                        }
                    }
                }
            }
            var goodsTableBody = $('.goods-tables tbody'),
                    otr = goodsTableBody.find('tr'),
                    proidArr = [];
            otr.each(function (i, item) {
                proidArr.push(parseInt($(this).attr('data-id')));
            });
            var htmlString = '';
            for (var index = 0 ; index < arr.length; index++){
                if( proidArr.length >0 && $.inArray(parseInt(arr[index].pro_id), proidArr) != -1 ){
                    continue;
                }else{
                    htmlString += '<tr data-id="'+arr[index].pro_id+'"><input type="hidden" name="proid[]" value="'+arr[index].pro_id+'" />' + '<td>' + arr[index]['pro_name']+ '</td>';
                    htmlString += '<td>' + arr[index]['pro_stock'] + '</td>' + '<td>'+arr[index]['pro_price']+'</td>';
                    htmlString += '<td> <button type="button" class="btn btn-red">删</button></td></tr>';
                }
            }
            goodsTableBody.append(htmlString);
        });
        $('.goods-tables').on('click', 'button.btn-red', function () {
            $(this).parents('tr').remove();
        });
    });
</script>
<include file="Common/footer" ftype="save" />